<?php

namespace App\Traits;


trait Rsa {
    public static $publicKey;
    public static $privateKey;

    public static function getPrivateKey(){
        $privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" . file_get_contents(base_path() . '/rsa/privateKey.key') . "\n-----END RSA PRIVATE KEY-----";
        return $privateKey;
    }
    public static function getPublicKey(){
        $publicKey = "-----BEGIN PUBLIC KEY-----\n" . file_get_contents(base_path() . '/rsa/publicKey.key') . "\n-----END PUBLIC KEY-----";
        return $publicKey;
    }
    public static function sign($data){
        openssl_sign($data, $sign, self::getPrivateKey());
        $sign = base64_encode($sign);
        return $sign;
    }

    public static function verify($data, $sign){
        $r = openssl_verify($data, base64_decode($sign), self::getPublicKey());
        return $r;
    }
}



















